package com.logic.modular.game.battle.process.skillEffectHandle.base;

import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffectServiceImpl;
import com.logic.modular.game.battle.panel.skillEffect.domain.SkillEffectStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 处理
 * 数值-覆盖|冲突
 */
@Slf4j
@Component
public class EffectHandle5 {
    public static final List<Integer> numericalCategory = new ArrayList<>(Arrays.asList(0, 1, 20));
    @Resource
    private PvpSkillEffectServiceImpl pvpSkillEffectService;

    /**
     * 处理
     * 数值-覆盖|冲突
     */
    public void tryCoverHandle(PvpSkillEffect skillEffect) {
        SkillEffectStatus status = skillEffect.getStatus();
        if (status.getStatus() == 0) {
            return;
        }

        Integer coreSkillEffectTypeType = skillEffect.getCoreSkillEffectTypeType();
        if (numericalCategory.contains(coreSkillEffectTypeType)) {// 数值类技能效果类型
            Long battleId = skillEffect.getBattleId();
            Long targetPlayerHeroId = skillEffect.getTargetPlayerHeroId();
            Long coreSkillEffectTypeId = skillEffect.getCoreSkillEffectTypeId();
            Integer coreSkillTyp = skillEffect.getCoreSkillTyp();

            PvpSkillEffect pvpSkillEffect = pvpSkillEffectService.eqSelect(
                    PvpSkillEffect.builder()
                            .battleId(battleId)
                            .targetPlayerHeroId(targetPlayerHeroId)
                            .coreSkillEffectTypeId(coreSkillEffectTypeId)
                            .coreSkillTyp(coreSkillTyp)
                            .build()
            );

            boolean has = pvpSkillEffect != null;

            if (has && status.getStatus() == 1) {
                Double source = pvpSkillEffect.getSkillEffectLayer().getThisChangeValue();
                source = Math.abs(source);

                Double change = skillEffect.getSkillEffectLayer().getThisChangeValue();
                change = Math.abs(change);
                boolean isOverwrite = source < change;
                if (isOverwrite) {
                    status.setStatus(3);


                } else {// 数值冲突
                    status.setStatus(0);
                    status.failReasons.add(-1);
                    log.info("数值冲突");
                }
            }
            skillEffect.setStatus(status);
        }
    }
}
